package com.lagou.kudu;

import org.apache.kudu.client.*;

/**
 * @program: kuduHomework
 * @description:
 * @author: Mr.Wang
 * @create: 2021-03-05 12:15
 **/
public class InsertKudu {
	public static void main(String[] args) {
		//地址
		String masterAddr = "node01";
		//创建客户端连接
		KuduClient client = new KuduClient.KuduClientBuilder(masterAddr)
				.defaultSocketReadTimeoutMs(6000).build();

		try {
			//获取表对象
			KuduTable table = client.openTable("student");
			//获取kudusession对象
			KuduSession kuduSession = client.newSession();
			//设置刷新及别
			kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
			kuduSession.setMutationBufferSpace(3000);
			//插入数据
			for (int i = 0; i <10 ; i++) {
				Insert insert = table.newInsert();
				insert.getRow().addInt("id",i);
				insert.getRow().addString("name",i+"号");
				kuduSession.flush();
				kuduSession.apply(insert);
			} kuduSession.close();
		} catch (KuduException e) {
			e.printStackTrace();
		} finally {
			try {
				if (client != null) {
					client.close();
				}
			} catch (KuduException e) {
				e.printStackTrace();
			}
		}

	}
}
